const app = getApp();
Page({
  data: {
    cndUrl: app.domainName,
    isX:'',
    tipNum:0,
    hideInfo:{a:'hide',b:'hide'}
  },
  onLoad: function (options) {
    var _this=this;
    wx.getSystemInfo({
      success: (res) => {
        if(res.screenHeight > 710){
          _this.setData({isX:'x-'});
        }
        console.log(res)
        console.log(res.screenHeight)
      }
    }); 
    
    wx.request({
      url: app.domainName + 'web/?c=getprize',
      method: 'POST',
    data: {o: app.globalData.openid
      }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) { 
          console.log(res);
          if(res.data.a == 'hide' || 'hide' == res.data.b){
            _this.setData({isX:'x-'});
          }
          _this.setData({ 
            'hideInfo.a': res.data.a,
            'hideInfo.b': res.data.b,
          });
      }
    });
     
  },
  onShow: function () {

  },
  doclick: function (e) {
    var _id=e.currentTarget.dataset.id;
    if('fztao' == _id){
      this.setData({ tipNum: 1});
      app.linkflow.sendEvent({"event": "UDE_403JET1HRZR","Click_Checkcoupons": "奖品列表页查看优惠券"})
      return;
     }
    if('popclose' == _id){
      this.setData({ tipNum: 0});
      return;
     }
     if('youfuzhi' == _id){
      wx.setClipboardData({
        data: '￥VsW71xtQ4gB￥',
        success (res) {}})
        app.linkflow.sendEvent({"event": "UDE_403CFDMIHJA","Click_copycoupon": "复制淘口令"})
      return;
    }
    if('youtu' == _id){
      this.saveImg(this.data.cndUrl+'img/reg/youhui-nx.png')
      app.linkflow.sendEvent({"event": "UDE_403TMNQDVQB","Click_saveofflinecoupon": "保存线下优惠券"})
      return;
    }
  },
  chawuliu: function () {
    var _this=this;
    wx.request({
      url: app.domainName + 'web/?c=getPath',
      method: 'POST',
      data: {op:  app.globalData.openid
      }, header: { 'content-type': 'application/x-www-form-urlencoded' },
      success: function (res) { 
        console.log(res);
        _this.setData({ tipNum: 4, wlPath:res.data});
      }
    });
  },
  saveImg(_url){
    let url = _url;
    //用户需要授权
    wx.getSetting({
      success: (res) => {
        if (!res.authSetting['scope.writePhotosAlbum']) {
          wx.authorize({
            scope: 'scope.writePhotosAlbum',
            success:()=> {
              // 同意授权
              this.saveImg1(url);
            },
            fail: (res) =>{
              console.log(res);
            }
          })
        }else{
          // 已经授权了
          this.saveImg1(url);
        }
      },
      fail: (res) =>{
        console.log(res);
      }
    })   
  },
  saveImg1(url){
    wx.getImageInfo({
      src: url,
      success:(res)=> {
        let path = res.path;
        wx.saveImageToPhotosAlbum({
          filePath:path,
          success:(res)=> { 
            console.log(res);
          },
          fail:(res)=>{
            console.log(res);
          }
        })
      },
      fail:(res)=> {
        console.log(res);
      }
    })
  },
  onShareAppMessage: function (res) {
    return {
      title: '联盟集结令，精致Girl都已经加入就差你了！',
      path: '/pages/index/index?share='+app.globalData.openid,
      imageUrl:'https://elixir.omnimkt.com/elixir07/img/64.png'
    }
  }
})